package ua.kpi_java_training.zabrodskyi.module2;

/**
 * @author Maksym Zabrodskyi
 * @version 10-Jun-2013
 */
public class Random {

    public static Position getFreePosition(Pool pool) {
        Position position = null;
        if (pool.hasFreeUnit()) {
            position = getPosition(pool);
            while (!pool.isFreePosition(position)) {
                position = getPosition(pool);
            }
        }
        return position;
    }

    private static Position getPosition(Pool pool) {
        int randomX = (int) (Math.random() * pool.getWidth());
        int randomY = (int) (Math.random() * pool.getHeight());
        return new Position(randomX, randomY);
    }

    public static int getStep(int maxStep) {
        return (int) (Math.random() * maxStep + 1);
    }

    public static Direction getDirection() {
        return Direction.values()[getIndex()];
    }

    private static int getIndex() {
        return (int) (Math.random() * Direction.values().length);
    }

}
